$(function () {
    findAll();

})

function findAll() {
    let businessCategoryModel = myAjax(ipAddress()+"/business/category/g/index", {}, "get",false);
    let companyModel = myAjax(ipAddress()+"/company/g", {}, "get",false);
    let newsModel = myAjax(ipAddress()+"/news/g/index", {}, "get",false);
    let businessPaterner =myAjax(ipAddress()+"/company/businessPaterner/g", {}, "get",false);

    if (businessCategoryModel != null) {

        setBusinessCategoryModel(businessCategoryModel.data);

        setCompanyInfo_synopsis(companyModel.data);

        console.log(newsModel);
        setNewsModel(newsModel.data);

        setBusinessPaterner(businessPaterner.data);

    }
}

function setBusinessCategoryModel(data) {
    let html='';
    for(let i=0;i<data.length;i++){
        html+='<div class="business">\n' +
            '                <div><img src="'+data[i].cateLogo+'" height="57" width="72"/></div>\n' +
            '                <div onclick="jumpBusinessCategory('+data[i].id+')">'+data[i].name+'</div>\n' +
            '                <div>'+data[i].cateSynopsis+
            '                </div>\n' +
            '            </div>';
    }
    $("#business").html(html);

}
function jumpBusinessCategory(id){
    sessionStorage.setItem("businessCategoryid",id);
    window.location.href="/html/business.html";
}


function setCompanyInfo_synopsis(data){

    let html= '                <div>\n' +
        '                    <img src="'+data.synopsisImg+'"width="165" height="200">\n' +
        '                </div>\n' +
        '            <div>\n' +
        '                <div>公司简介 / About Us</div>\n' +
        '                <div>'+data.synopsis+'\n' +
        '                </div>\n' +
        '                <div style="cursor: pointer;" onclick="jumpCompanySynopsis()">查看更多>></div>\n' +
        '            </div>';
    $("#synopsis").html(html);
}
// 查看更多的跳转页
function jumpCompanySynopsis(){
   window.location.href="/html/about.html";
}


function setNewsModel(data) {
    let html='';

    for(let j=0;j<data.length;j++){
        if(data[j].isCover==1){
            html+=' <div onclick="jumpNewsCenter()">\n' +
                '                <img src="'+data[j].imgHref+'"/>\n' +
                '            </div>\n' +
                '            <div>';
        }
    }
    for(let i=0;i<data.length;i++) {
        if (data[i].isHot == 1) {
            html += '    <div>\n' +
                '        <div style="cursor: pointer" onclick="jumpNewsDetail('+data[i].id+')"><img src="' + data[i].imgHref + '"/></div>\n' +
                '        <div class="news-font">\n' +
                '            <div style="cursor: pointer" onclick="jumpNewsDetail('+data[i].id +')">' + data[i].name + '</div>\n' +
                '            <div>' + data[i].createTime.substring(0, 11) + '<br>\n' +
                '                ' + data[i].content + '\n' +
                '            </div>\n' +
                '        </div>\n' +
                '    </div>';
        }
    }
    html+='</div>';
    $("#news").html(html);
}

function jumpNewsCenter(){
    sessionStorage.clear();
    window.location.href="/html/news.html";
}
function jumpNewsDetail(id){
    sessionStorage.setItem("newsDId",id)
    window.location.href="/html/news-detail.html";
}

function setBusinessPaterner(data) {

    let html='';
    for(let i=0;i<data.length;i++) {
       html+='<div><img src="'+data[i].partnerImg+'"></div>';
    }
    $("#partner").html(html);
}


